import pandas as pd
df1 = pd.DataFrame([['李明','M',18,'北京'],
                    ['张华','M',19,'天津'],
                    ['刘涛','F',20,'上海'],
                    ['王阳','F',14,'广州'],
                    ['李春','F',16,'深圳']],
                    index=['one', 'two', 'three', 'four','five'],
                    columns=['name','gender','age','city'])
print(df1)

data = df1[['name']][:3]
print('访问name列前3行的数据：')
print(data)

data = df1.loc[:,'name']
print('使用loc获取name列数据的结果:\n',data)
data=df1.loc['three',['name','city']]
print('获取第3行name列和city列数据的结果:\n',data)
data=df1.loc['two':'four',['name','age']]
print('获取第2行name列和第4行age列数据的结果:\n',data)

data =df1.iloc[0]
print ('获取第0行数据的结果\n',data)
data = df1.iloc[[1,2],[3,0,1]]
print ('获取第1和第2行中第3、0和1列数据的结果：\n',data)
data=df1.iloc[:, :3][df1.age > 18]
print('选取前3行中C列中大于18的结果\n',data)